/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.clarice.homechef.controllers;

import com.clarice.homechef.constants.Constants;
import com.clarice.homechef.domain.Bill;
import com.clarice.homechef.domain.Orders;
import com.clarice.homechef.service.BillService;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author Akshay Velhal
 */
@RestController
@RequestMapping("/api")
public class BillController {

    @Autowired
    BillService billService;

    @RequestMapping(value = "/bill", method = RequestMethod.POST)
    public @ResponseStatus(value = HttpStatus.CREATED)
    void createNewBill(
            HttpServletResponse response,
            @RequestHeader(Constants.NT_LOGIN) String userName,
            @RequestBody List<Orders> orders) throws Exception {
        System.out.println("Post: create new Bill for " + userName);
        billService.createNewBill(userName, orders);
    }

    @RequestMapping(value = "/cartdetails", method = RequestMethod.POST)
    public Bill getCartDetails(
            HttpServletResponse response,
            @RequestHeader(Constants.NT_LOGIN) String userName,
            @RequestBody List<Orders> orders) throws Exception {
        System.out.println("Post: create new Bill for " + userName);
        return billService.getCartDetails(userName, orders);
    }
}
